﻿@{
    Layout = "~/_NoBodyLayout.cshtml";
    Page.Title = "RoadFlow";
    Page.CheckApp = false;
    Page.CheckUrl = false;
    
    Business.Platform.UsersRole buserRole = new Business.Platform.UsersRole();
    Business.Platform.Role brole = new Business.Platform.Role();
    var roles = buserRole.GetByUserID(Business.Platform.Users.CurrentUserID);
    string defaultRoleID = string.Empty;
    string rolesOptions = string.Empty;
    if (roles.Count > 0)
    {
        var mainRole = roles.Find(p => p.IsDefault);
        defaultRoleID = mainRole != null ? mainRole.RoleID.ToString() : roles.First().RoleID.ToString();
        List<Data.Model.Role> roleList = new List<Data.Model.Role>();
        foreach(var role in roles)
        {
            var role1 = brole.Get(role.RoleID);
            if(role1==null)
            {
                continue;
            }
            roleList.Add(role1);
        }

        rolesOptions = brole.GetRoleOptions("", "", roleList);
    }

    var user = Business.Platform.Users.CurrentUser;
    string userName = user == null ? "" : user.Name;
    string dateTime = Utility.DateTimeNew.Now.ToDateWeekString();
}

<body class="mainBody">
<style type="text/css">
    html,body {overflow:hidden; }
</style>
<div class="mainTop">
    <div class="mainTopLeft"></div>
    <div class="mainTopRight">
        <div style="height:18px;"></div>
        <div style="padding-right:20px;">
            <div>
                <span style="margin-right:0px; background:url(/images/ico/member.gif) no-repeat left; padding-left:18px;">欢迎您：@userName</span>
                <span style="margin-right:6px;"></span>
                <span style="margin-right:6px;">日期：<span id="CurrentDateTimeSpan">@dateTime</span></span>
                <span style="">主题：</span>
                <span class="mainTheme_bluelight" onclick="changeTheme('BlueLight');"></span>
                <span class="mainTheme_blue" onclick="changeTheme('Blue');"></span>
                <span class="mainTheme_green" onclick="changeTheme('Green');"></span>
                <span class="mainTheme_gray" onclick="changeTheme('Gray');"></span>
            </div>
            <div style="margin-top:8px;">
                <span style="margin-right:6px;"><a href="javascript:void(0);" onclick="openApp('/Home',0,'首页','index'); return false;" class="white" >首&nbsp;&nbsp;页</a></span>
                <span style="margin-right:6px;">|</span>
                <span style="margin-right:6px;"><a href="javascript:void(0);" onclick="openApp('/Platform/System/EditPass',2,'修改密码','index_editpass',500,210); return false;" class="white" >修改密码</a></span>
                <span style="margin-right:6px;">|</span>
                <span style="margin-right:4px;"><a href="javascript:void(0);" onclick="if(confirm('您真的要退出系统吗?')){window.location='Quit';} return false;" class="white" >退出系统</a></span>
            </div>
        </div>
    </div>
    <div style="clear:both;"></div>
</div>
<div class="mainDiv">
<table cellpadding="0" cellspacing="0" width="100%" border="0" style="table-layout:fixed;">
    <tr>
        <td class="mainMenutd" id="mainMenutd" >
            <div class="menuDiv1" onclick="switchMenu(false);"></div>
            <div class="menuDiv">
                <div class="menuDivTitle">
                    <div class="menuDivTitlel">管理目录</div>
                    <div class="menuDivTitler" onclick="switchMenu(true);"></div>
                </div>
                    
                <div style="padding:0 4px 0 8px;" id="RoleDiv" runat="server">
                    <select class="myselect" style="width:135px; height:24px; margin-top:4px;" id="MyRole" name="MyRole" onchange="roleChange(this.value);">
                        @Html.Raw(rolesOptions)
                    </select>
                </div>
                <div id="treeDiv" style="margin:0; overflow:auto;  padding:3px 3px 0 4px; "></div>
            </div>
        </td>
        <td class="mainSplittd" id="mainSplittd"></td>
        <td style="vertical-align:top;">
            <div id="mainTabDiv" class="mainTabDiv"></div>
        </td>
    </tr>
</table>
</div>
<script type="text/javascript">
    var mainTab = null;
    var mainTree = null;
    var mainDialog = new RoadUI.Window();
    var defaultRoleID = "@defaultRoleID";
    var currentDateTimeSpan = $("#CurrentDateTimeSpan");
    var rolesLength = @roles.Count;
    var userID = '@Business.Platform.Users.CurrentUserID';
    $(function ()
    {
        if (rolesLength <= 1)
        {
            $("#MyRole").hide();
        }

        $('#mainTabDiv').height($(window).height() - 75);
        $('#treeDiv').height($(window).height() - (rolesLength > 1 ? 133 : 104));

        $(window).bind('resize', function ()
        {
            $('#mainTabDiv').height($(window).height() - 75);
            $('#treeDiv').height($(window).height() - (rolesLength > 1 ? 133 : 104));
            mainTab.topResize($(window).height() - 101);
        });

        mainTab = new RoadUI.Tab({ id: "mainTabDiv", replace: true });
        roleChange(defaultRoleID);
        openApp("/Home", 0, "首页", "index");

        //初始化主题按钮样式
        var theme = $.cookies.get("theme_platform") || "BlueLight";
        changeTheme(theme);
    });

    function update()
    {
        $.ajax({ url: "", cache: false, async: true, success: function (txt)
        {
            currentDateTimeSpan.html(txt);
            window.setTimeout(update, 10000);
        },
            error: function ()
            {
                window.setTimeout(update, 20000);
            }
        });
    }

    function treeClick(json)
    {
        if (json)
        {
            openApp(json.link, json.model, json.title, json.id, parseInt(json.width), parseInt(json.height), true);
        }
    }

    function openApp(url, model, title, id, width, height, isAppendParams)
    {
        if (!url || url.toString().length == 0)
        {
            return;
        }
        if (!id)
        {
            id = RoadUI.Core.newid();
        }
        if (width == 0) width = undefined;
        if (height == 0) height = undefined;
        if (isAppendParams)
        {
            url += url.indexOf('?') >= 0 ? "&appid=" + id : "?appid=" + id;
        }
        switch (parseInt(model))
        {
            case 0:
                mainTab.addTab({ id: "tab_" + id.replaceAll('-', ''), title: title, src: url });
                break;
            case 1:
                mainDialog.open({ id: "window_" + id.replaceAll('-', ''), title: title, url: url, width: width || 800, height: height || 460, ismodal: false });
                break;
            case 2:
                mainDialog.open({ id: "window_" + id.replaceAll('-', ''), title: title, url: url, width: width || 800, height: height || 460, ismodal: true });
                break;
        }
    }

    function switchMenu(flag)
    {
        if (flag)
        {
            $("#mainMenutd").removeClass().addClass("mainMenutd1");
            $(".menuDiv").hide(200);
            $(".menuDiv1").show(100);
        }
        else
        {
            $("#mainMenutd").removeClass().addClass("mainMenutd");
            $(".menuDiv").show();
            $(".menuDiv1").hide();
        }
    }

    function roleChange(roleID)
    {
        $("#treeDiv").html("");
        mainTree = new RoadUI.Tree({ id: "treeDiv", path: "/Menu?roleid=" + roleID + "&userid=" + userID, refreshpath: "/MenuRefresh?roleid=" + roleID + "&userid=" + userID, showroot: true, onclick: treeClick });
    }

    function changeTheme(themeName)
    {
        $("span[class^='mainTheme_']").each(function ()
        {
            var cssName = $(this).attr("class");
            $(this).removeClass().addClass(cssName.replace("1", ""));
            
        });
        try
        {
            themeName=themeName.toLowerCase();
            var current=$(".mainTheme_" + themeName)||$(".mainTheme_" + themeName+"1");
            current.removeClass().addClass("mainTheme_" + themeName + "1");
        }
        catch(e){}
        new RoadUI.Init().theme(themeName);
    }
</script>